//
//  SCRadioMoreViewController.m
//  LastOne
//
//  Created by dllo on 15/11/3.
//  Copyright © 2015年 sc. All rights reserved.
//

#import "SCRadioMoreViewController.h"
#import "SCAudioVisualTableView.h"
#import "HTTPMethod.h"
#import "SCRadioMoreTableViewCell.h"
#import "NightHeader.h"
#import "SCRadioPlayViewController.h"
#import "GiFHUD.h"
#import "FitHeader.h"
@interface SCRadioMoreViewController ()<UITableViewDataSource, UITableViewDelegate>
@property(nonatomic, strong)UITableView *tableView;
@property(nonatomic, strong)NSMutableArray *dataRadioListArray;
@end

@implementation SCRadioMoreViewController



- (void)viewDidLoad {
    [super viewDidLoad];
     self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = _radioSectionModel.cname;
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}
- (void)loadView
{
    [super loadView];
        //加载页面
    [self getData];
    [GiFHUD setGifWithImageName:@"dongtu.gif"];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView NightWithType:UIViewColorTypeNormal];
    _tableView.tableFooterView = [[UITableView alloc] init];
    [self.view addSubview:_tableView];
    
    [GiFHUD setGifWithImageName:@"loading.gif"];


}
- (void)getData
{
    [GiFHUD show];
    self.dataRadioListArray = [NSMutableArray array];
    [HTTPMethod getDataByString:[NSString stringWithFormat:@"http://c.m.163.com/nc/topicset/android/radio/%@/0-20.html", _radioSectionModel.cid] BodyDic:nil WithDataBlock:^(id data) {
        for (NSDictionary *tListDic in [data objectForKey:@"tList"]) {
            NSDictionary *radioDic = [NSDictionary dictionaryWithDictionary:[tListDic objectForKey:@"radio"]];
            SCRadioModel *radioModel = [[SCRadioModel alloc] init];
            [radioModel setValuesForKeysWithDictionary:radioDic];
            radioModel.tid = [tListDic objectForKey:@"tid"];
            [_dataRadioListArray addObject:radioModel];
        }
        [_tableView reloadData];
       [GiFHUD dismiss];
    }];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 120 * FitHeight;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataRadioListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"cell";
    SCRadioMoreTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[SCRadioMoreTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.titleLabel.textType = [NSNumber numberWithInteger:LabelColorGray];
    [cell NightWithType:UIViewColorTypeNormal];
    [cell.titleLabel NightWithType:UIViewColorTypeNormal];
    if (_dataRadioListArray.count != 0) {
        
        cell.radioModel = _dataRadioListArray[indexPath.row];
    }
    cell.selectionStyle = NO;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SCRadioPlayViewController *rvc = [[SCRadioPlayViewController alloc] init];
    rvc.radioModel = _dataRadioListArray[indexPath.row];
    [self.navigationController pushViewController:rvc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
